import request from "@/utils/request";
import type { RequestParams, ResponseData, BookRequestParams } from "./type";

// 分页列表
export const bookList = (data: RequestParams) => {
  return request<ResponseData<BookRequestParams>, any>({
    url: "/api/v1/bookshelfToChina/page",
    method: "post",
    data,
    headers: {
      //需要加密的请求在头部塞入标识
      isEncrypt: 1,
    },
  });
};
export const addbook = (data: BookRequestParams) => {
  return request<ResponseData<BookRequestParams>, any>({
    url: "/api/v1/bookshelfToChina/add",
    method: "post",
    data,
    headers: {
      //需要加密的请求在头部塞入标识
      isEncrypt: 1,
    },
  });
};
export const delbook = (id: number) => {
  return request<ResponseData<BookRequestParams>, any>({
    url: "/api/v1/bookshelfToChina/delete",
    method: "post",
    data: id,
    headers: {
      //需要加密的请求在头部塞入标识
      isEncrypt: 1,
    },
  });
};
export const Formbook = (id: number) => {
  return request<ResponseData<BookRequestParams>, any>({
    url: "/api/v1/bookshelfToChina/form",
    method: "post",
    data: id,
    headers: {
      //需要加密的请求在头部塞入标识
      isEncrypt: 1,
    },
  });
};

export const LibraryOptions = (aesKeyByRsa: string) => {
  return request<ResponseData<any>, any>({
    url: "/api/v1/library/options",
    method: "post",
    data: aesKeyByRsa,
    headers: {
      //需要加密的请求在头部塞入标识
      isEncrypt: 1,
    },
  });
};
export const updatebook = (data: BookRequestParams) => {
  return request<ResponseData<BookRequestParams>, any>({
    url: "/api/v1/bookshelfToChina/update",
    method: "post",
    data,
    headers: {
      //需要加密的请求在头部塞入标识
      isEncrypt: 1,
    },
  });
};

/**
 * 导入
 *
 * @param queryParams
 * @returns
 */

export function importBook(file: File) {
  const formData = new FormData();
  formData.append("file", file);
  return request<ResponseData<any>, any>({
    url: `/api/v1/bookshelfToChina/import`,
    method: "post",
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
    //timeout: 30000,
  });
}
